package com.weiweiqin.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.weiweiqin.dao.GoodsDao;
import com.weiweiqin.model.Goods;
import com.weiweiqin.model.GoodsCategoryItem;
import com.weiweiqin.model.GoodsPicItem;
import com.weiweiqin.model.Pic;
@Repository
public class GoodsDaoImpl extends GenericMybatisDao<Goods, Integer>
		implements GoodsDao {

	@SuppressWarnings("unchecked")
	public List<Goods> getListByCategoryId(int categoryId) {
		
		return ( List<Goods>)getSqlSession().selectList("Goods_getByCategoryId",categoryId);
	}
	
	@SuppressWarnings("unchecked")
	public List<Pic> getTitlePicListById(int id) {
		return  ( List<Pic>)getSqlSession().selectList("Goods_getTiltePicListById",id);
	}

	@SuppressWarnings("unchecked")
	public List<Pic> getPicListById(int id) {
		return  ( List<Pic>)getSqlSession().selectList("Goods_getPicListById",id);
	}

	@SuppressWarnings("unchecked")
	public List<GoodsPicItem> getPicItemListById(int id) {
		return ( List<GoodsPicItem>)getSqlSession().selectList("Goods_getPicItemListById",id);
	}

	public GoodsCategoryItem getCategoryItemById(int id) {
		return (GoodsCategoryItem) getSqlSession().selectOne("Goods_getCategoryItemById",id);
	}

	@SuppressWarnings("unchecked")
	public List<Goods> getAll() {
		return ( List<Goods>)getSqlSession().selectList("Goods_getAll");
	}

	@SuppressWarnings("unchecked")
	public List<Goods> getByPicName(String picName) {
		return (List<Goods>) getSqlSession().selectList("Goods_getByPicName",picName);
	}

	@SuppressWarnings("unchecked")
	public List<Goods> getByName(String title) {
		Map<String,Object> condition = new HashMap<String,Object>();
		condition.put("title", title);
		return (List<Goods>) getSqlSession().selectList("Goods_getByName",condition);
	}

	public String getKeysById(int id) {
		return (String) getSqlSession().selectOne("Goods_getKeysById",id);
	}


	public int staticSign(int goodsId, String startDate, String endDate,
			int status1, int status2) {
		Map<String,Object> condition = new HashMap<String,Object>();
		condition.put("goodsId", goodsId);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("status1", status1);
		condition.put("status2", status2);
		return (Integer) getSqlSession().selectOne("Goods_staticSign",condition);
	}
	
}